<template>
  <u-popup :show="show">
    <view class="popup-wrap">
      <view class="popup-header">
        <view class="popup-header__cancel" @click="handleCloseRefuse">取消</view>
        <view class="popup-header__title">{{title}}</view>
        <view class="popup-header__confirm" @click="handleConfirmRefuse">确认</view>
      </view>
      <view class="popup-body">
        <radio-group class="reason-list" @change="radioChange">
          <label class="reason-list-item" v-for="item in reasonList" :key="item">
            <view class="reason-list-item__text">{{item}}</view>
            <radio class="reason-list-item__radio" :value="item" :checked="item === currentReason" />
          </label>
        </radio-group>
      </view>
    </view>
  </u-popup>
</template>
<script>
import { CompanyRefuseReasonList, CustomerRefuseReasonList } from "../utils/constants";

export default {
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    isCompany: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      currentReason: '',
    }
  },
  computed: {
    reasonList() {
      return this.isCompany ? CompanyRefuseReasonList : CustomerRefuseReasonList
    },
    title() {
      if (this.isCompany) {
        return '选择原因，为您优化推荐'
      }
      return '选择原因，减少不合适职位推荐'
    },
  },
  methods: {
    radioChange(e) {
      this.currentReason = e.detail.value;
    },
    handleCloseRefuse() {
      this.currentReason = '';
      this.$emit('close');
    },
    handleConfirmRefuse() {
      if (!this.currentReason) {
        uni.showToast({
          title: '请选择原因',
          icon: 'none',
          duration: 3000
        })
        return
      }
      this.$emit('confirm', this.currentReason);
      this.currentReason = '';
    }
  }
}
</script>
<style lang="scss">
.popup-wrap {
  background: #f7f7f7;

  .popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 15px 10px;
    background: #fff;

    .popup-header__cancel {
      font-size: 15px;
      color: #888888;
      line-height: 24px;
      padding: 0 5px;
    }

    .popup-header__title {
      flex: 1;
      width: 0;
      text-align: center;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      font-weight: 700;
      font-size: 16px;
      color: #333333;
      line-height: 25px;
    }

    .popup-header__confirm {
      font-size: 15px;
      color: #37AF71;
      line-height: 24px;
      padding: 0 5px;
    }
  }

  .popup-body {
    padding: 10px;

    .reason-list {
      width: 100%;
      display: block;
    }

    .reason-list-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 12px 20px;
      background: #fff;
      border-radius: 4px;
      margin-bottom: 10px;

      &:last-child {
        margin-bottom: 0;
      }

      .reason-list-item__text {
        flex: 1;
        width: 0;
        font-weight: 500;
        font-size: 14px;
        color: #333333;
      }

      .reason-list-item__radio {
        transform:scale(0.9);
      }
    }
  }
}
</style>
